<!--招生学生管理学生列表-->
<div class="layui-fluid layui-anim febs-anim" id="businesses-networkSchool" lay-title="账号管理">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="college-table-form">
<!--                        <input id="stuList-userId" type="hidden" data-th-value="${user.userId}">-->
                        <fieldset class="layui-elem-field layui-field-title" style="">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md12">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">批次</label>
                                        <div class="layui-input-inline">
                                            <select name="batchId" id="businesses-networkSchool-stubatch-select" lay-search="">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">院校</label>
                                        <div class="layui-input-inline">
                                            <select name="collegeId" id="businesses-networkSchool-stucollege-select" lay-search="">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">层次</label>
                                        <div class="layui-input-inline">
                                            <select name="level" id="businesses-networkSchool-level-select" lay-search="">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">类别</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectId" id="businesses-networkSchool-cboType-select" lay-filter="cboType_TeachProgram" lay-search="">

                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">专业</label>
                                        <div class="layui-input-inline">
                                            <select name="majorId" id="businesses-networkSchool-major-select" lay-search="">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">报名费</label>
                                        <div class="layui-input-inline">
                                            <select name="originalPrice" id="businesses-networkSchool-originalPrice-select" lay-search="">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">招生老师</label>
                                        <div class="layui-input-inline">
                                            <div class="layui-input-inline">
                                                <input type="text" name="userId" id="businesses-networkSchool-teacher-select"
                                                       lay-filter="businesses-networkSchool-teacher-select" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <fieldset class="layui-elem-field layui-field-title" style="">
                            <legend style="font-size: 15px; font-weight: bolder;">精准查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md11">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">姓名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="realName" autocomplete="off" class="layui-input"
                                                   id="businesses-networkSchool-stuName-input" lay-verify="txt" maxlength="15"></div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">身份证</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="identity" autocomplete="off" class="layui-input"
                                                   id="businesses-networkSchool-stuIdidentity-input" lay-verify="dimIdentity" maxlength="18">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">电话</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tel" autocomplete="off" class="layui-input"
                                                   id="businesses-networkSchool-stuTel-input" lay-verify="number" maxlength="11"></div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">账号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="username" autocomplete="off" class="layui-input"
                                                   id="businesses-networkSchool-username-input" lay-verify="txt"></div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">短信时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="beginDate" placeholder="请选择开始时间" id="businesses-networkSchool-beginDate-input" lay-verify="datetime" class="layui-input">
                                        </div>

                                        <div class="layui-form-mid" style="padding-bottom: 15px">-</div>
                                        <div class="layui-input-inline">
                                            <input type="text" name="endDate" placeholder="请选择结束时间" id="businesses-networkSchool-endDate-input" lay-verify="datetime" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md1 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     lay-submit lay-filter="businesses-networkSchool-query-btn" id="businesses-networkSchool-query-btn">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                     id="businesses-networkSchool-reset-btn" lay-filter="businesses-networkSchool-reset-btn">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table id="businesses-networkSchool-student-table" lay-filter="businesses-networkSchool-student-table" lay-data="{id: 'businesses-networkSchool-student-table'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--列表头部工具栏-->
<script type="text/html" id="businesses-networkSchool-toolBar">
    <div class="layui-row">
        <!--    id用与js绑定    -->
        <button type="button" class="layui-btn  layui-btn-sm layui-btn-primary febs-button-blue-plain"
                id="businesses-networkSchool-downloadModel-btn">
            <i class="layui-icon" >&#xe82a;</i> 下载模板
        </button>
        <!--    id用与js绑定    -->
        <button type="button" class="layui-btn  layui-btn-sm layui-btn-success" id="businesses-networkSchool-import-btn">
            <i class="layui-icon" >&#xe7a8;</i> 导入
        </button>
        <!--    id用与js绑定    -->
        <button type="button" class="layui-btn  layui-btn-sm layui-btn-primary febs-button-green-plain" style="margin-left: 10px"
                id="businesses-networkSchool-export-btn">
            <i class="layui-icon" >&#xe7aa;</i> 导出
        </button>
    </div>
</script>
<script type="text/html" id="businesses-networkSchool-option">
    <a lay-event="detail" title="重置账号信息"><i
            class="layui-icon layui-icon-sync febs-red"></i></a>
    <a lay-event="remark" title="添加备注"><i
            class="layui-icon layui-icon-edit febs-blue"></i></a>
</script>
<script type="text/javascript" src="module/treeSelect/treeSelect.js"></script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'form', 'table', 'febs', 'validate', 'laydate', 'treeSelect', 'upload'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            // 得到upload对象
            upload = layui.upload,
            validate = layui.validate,
            treeSelect = layui.treeSelect,
            $view = $('#businesses-networkSchool'),
            $query = $view.find('#businesses-networkSchool-query-btn'),
            $reset = $view.find('#businesses-networkSchool-reset-btn'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createDate', type: null},
            tableIns;

        form.render();
        initTable();
        initDate();
        form.verify(validate);
        //导入按钮
        uploadRender();

        table.on('tool(businesses-networkSchool-student-table)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                febs.modal.confirm('提示', '确定要重置账号信息吗？', function () {
                    $.ajax({
                        url: "networkSchool/resetNetworkSchool",
                        data: {username: data.username},
                        success: function (data) {
                            if (data.code == 200) {
                                febs.alert.success('重置信息成功');
                            }else {
                                febs.alert.error('重置信息失败');
                            }
                            $query.click();
                        },
                    });
                });
            };
            if (layEvent === 'remark') {
                layer.open({
                    type: 1
                    ,title: '备注' //不显示标题栏
                    ,closeBtn: false
                    ,area: '400px;'
                    ,shade: 0.8
                    ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    ,btn: ['提交', '取消']
                    ,btnAlign: 'c'
                    ,moveType: 1 //拖拽模式，0或者1
                    ,content: '<div style="padding:5px; width: 388px; height: 200px; line-height: 200px; color: #fff; font-weight: 300;' +
                        'text-align: center"><textarea id="txt-networkSchool-remark" name="remark" maxlength="200" ' +
                        'class="layui-textarea" placeholder="请填写备注"></textarea></div>'
                    ,success: function(layero){
                        var btn = layero.find('.layui-layer-btn');
                        btn.find('.layui-layer-btn0').click(function() {
                            let remark = $('#txt-networkSchool-remark').val();
                            $.ajax({
                                url: ctx + 'networkSchool/remark',
                                data: {remark: remark,username: data.username},
                                success: function (res) {
                                    if (res.code == 200){
                                        febs.alert.success('添加备注成功');
                                    }else {
                                        febs.alert.error('添加备注失败');
                                    };
                                    $query.click();
                                }
                            })
                        });
                    }
                });
            }
        });

        //导入方法
        function uploadRender(){
            // 创建一个上传组件
            upload.render({
                // 绑定列表头部工具栏的导入id
                elem: '#businesses-networkSchool-import-btn',
                // 访问路由
                url: ctx + 'networkSchool/import',
                // 指定允许上传时校验的文件类型，可选值有：images（图片）、file（所有文件）、video（视频）、audio（音频）
                accept: 'file',
                // 允许上传的文件后缀。一般结合 accept 参数类设定。假设 accept 为 file 类型时，那么你设置 exts: 'zip|rar|7z'
                // 即代表只允许上传压缩格式的文件。如果 accept 未设定，那么限制的就是图片的文件格式
                exts: 'xlsx', // 只能上传 .xlsx格式
                // 设置文件最大可允许上传的大小，单位 KB。不支持ie8/9
                size: 5 * 1024, // kb
                // 文件提交上传前的回调。返回一个object参数（同上）
                before: function () {
                    febs.view.loadBar.start();
                },
                // 执行上传请求后的回调。返回三个参数，分别为：res（服务端响应信息）、index（当前文件的索引）、upload（重新上传的方法，一般在文件上传失败后使用）
                done: function (res) {
                    if (res.message == 200) {
                        // 重新渲染表格
                        febs.view.loadBar.finish();
                        febs.alert.success('导入成功！');
                        let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                        tableIns.reload({where: params, page: {curr: 1}, cols: [mycols]});
                    } else if (res.message == 400) {
                        febs.view.loadBar.error();
                        febs.alert.error('导入失败！');
                        // 弹出导入错误日志框，可查看导入失败的具体数据
                        febs.modal.view('错误日志', 'entranceScore/errorResult', {
                            area: $(window).width() <= 750 ? '95%' : '1000px'
                        });

                    } else {
                        // 弹出异常提示框
                        febs.view.loadBar.error();
                        febs.alert.error('文件异常！');
                    }
                }
            });
        }

        // 下载导入模板文件
        // 与列表顶部操作栏下载模板id绑定
        $view.on('click', '#businesses-networkSchool-downloadModel-btn', function () {
            // febs.download（路径，传入后台的参数，下载后的文件名）
            febs.download(ctx + 'networkSchool/downloadNetwork', null, '233网校账号导入模板.xlsx');
        });

        //在个位数的时间前加0
        function formatZero(n){
            if(n>=0&&n<=9){
                return "0"+n;
            }else{
                return n;
            }
        }

        //导出数据
        // 与列表顶部操作栏导出id绑定
        $view.on('click', '#businesses-networkSchool-export-btn', function () {
            // 传入后台的参数
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
            params.pageNum = $view.find(".layui-laypage-em").next().html();
            //拼接时间
            var add='';
            var t=new Date();
            var year=t.getFullYear();
            var month=t.getMonth()+1;
            var day=t.getDate();
            var hours=t.getHours();
            var minutes=t.getMinutes();
            var seconds=t.getSeconds();
            add=year+formatZero(month)+formatZero(day)+"_"+formatZero(hours)+formatZero(minutes)+formatZero(seconds)+".xlsx";
            // 访问路由
            febs.download(ctx + 'networkSchool/excel', params, '233用户'+add);
        });

        function initDate() {
            var beginDate = laydate.render({//渲染开始时间选择
                elem: '#businesses-networkSchool-beginDate-input', //通过id绑定html中插入的start
                type: 'date',
                max: "2099-12-31",//设置一个默认最大值
                done: function (value, dates) {
                    endDate.config.min = {
                        year: dates.year,
                        month: dates.month - 1, //关键
                        date: dates.date,
                        hours: dates.hours,
                        minutes: dates.minutes,
                        seconds: dates.seconds
                    };
                }
                ,btns: ['clear', 'confirm']
            });
            var endDate = laydate.render({//渲染结束时间选择
                elem: '#businesses-networkSchool-endDate-input',//通过id绑定html中插入的end
                type: 'date',
                min: "1970-1-1",//设置min默认最小值
                done: function (value, dates) {
                    beginDate.config.max = {
                        year: dates.year,
                        month: dates.month - 1,//关键
                        date: dates.date,
                        hours: dates.hours,
                        minutes: dates.minutes,
                        seconds: dates.seconds
                    }
                }
                ,btns: ['clear', 'confirm']
            });
        }

        treeSelect.render({
            // 选择器
            elem: '#businesses-networkSchool-teacher-select',
            // 数据
            data: ctx + 'transferApplication/userDeptTree',
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '请选择',
            // 是否开启搜索功能：true/false，默认false
            search: true,
            style: {
                folder: { // 父节点图标
                    enable: true // 是否开启：true/false
                },
                line: {
                    enable: true
                }
            },
            // 点击回调
            click: function (d) {
                $("#businesses-networkSchool-teacher-select").val(d.current.id);
            },
            // 加载完成后的回调函数
            success: function (d) {

            }
        });

        $(".layui-input").keydown(function (e) {//当按下按键时
            if (e.which == 13) {//.which属性判断按下的是哪个键，回车键的键位序号为13
                $query.click();
            }
        });

        //批次
        febs.get('/student/batchList', null, function (data) {
            let list = data.data;
            for (let i = 0; i < list.length; i++) {
                $("#businesses-networkSchool-stubatch-select").append(new Option(list[i].batchName, list[i].id));
            }
            //重新渲染下拉菜单
            form.render("select");
        });

        //院校
        febs.get('/student/collegeList', null, function (data) {
            let list = data.data;
            for (let i = 0; i < list.length; i++) {
                $("#businesses-networkSchool-stucollege-select").append(new Option(list[i].name, list[i].id));
            }
            //重新渲染下拉菜单
            form.render("select");
        });

        //层次
        febs.get('/student/stuLevelList', null, function (data) {
            let list = data.data;
            for (let i = 0; i < list.length; i++) {
                $("#businesses-networkSchool-level-select").append(new Option(list[i].levelName, list[i].id));
            }
            //重新渲染下拉菜单
            form.render("select");
        });

        //报名费
        febs.get('/networkSchool/originalPrice', null, function (data) {
            let list = data.data;
            for (let i = 0; i < list.length; i++) {
                $("#businesses-networkSchool-originalPrice-select").append(new Option(list[i].price, list[i].price));
            }
            //重新渲染下拉菜单
            form.render("select");
        });

        //专业
        febs.get('/student/majorList', null, function (data) {
            let list = data.data;
            for (let i = 0; i < list.length; i++) {
                $("#businesses-networkSchool-major-select").append(new Option(list[i].fullName, list[i].id));
            }
            //重新渲染下拉菜单
            form.render("select");
        });

        //类别下拉框
        initSubject();
        function initSubject() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/subjectCategoryList',
                success: function (res) {

                    $("#businesses-networkSchool-cboType-select").append("<option value=''>请选择</option>")
                    layui.each(res.data, function (index, item) {
                        $("#businesses-networkSchool-cboType-select").append("<option value='" + this.id + "'>" + this.fullName + "</option>");
                    });
                    //渲染select
                    form.render('select');

                }
            })
        }

        table.on('sort(businesses-networkSchool-student-table)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        //表单提交事件-查询
        form.on('submit(businesses-networkSchool-query-btn)', function (data) {
            let myBeginDate = $('#businesses-networkSchool-beginDate-input').val();
            let myEndDate = $('#businesses-networkSchool-endDate-input').val();
            if(myBeginDate==""){
                myBeginDate = "";
            }
            if(myEndDate==""){
                myEndDate = "";
            }
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
            $('#businesses-networkSchool-beginDate-input').val(myBeginDate);
            $('#businesses-networkSchool-endDate-input').val(myEndDate);
            return false;
        });

        //重置表单
        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}});
            $('#businesses-networkSchool-beginDate-input').val("");
            $('#businesses-networkSchool-endDate-input').val("");
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'businesses-networkSchool-student-table',
                url: ctx + 'networkSchool/list',
                toolbar: '#businesses-networkSchool-toolBar',
                defaultToolbar: ['filter'],
                done: function (res, curr, count) {
                    $("table").css("width", "100%");
                },
                width: "100%",
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '编号', minWidth: 60},
                    {field: 'username', title: '账号', minWidth: 80},
                    {field: 'password', title: '密码', minWidth: 80},
                    {field: 'realName', title: '姓名', minWidth: 80},
                    {field: 'name', title: '院校', minWidth: 80},
                    {field: 'batchName', title: '批次', minWidth: 80},
                    {field: 'levelName', title: '层次', minWidth: 80},
                    {field: 'fullName', title: '专业', minWidth: 80},
                    {field: 'subjectName', title: '类别', minWidth: 80},
                    {field: 'recruitName', title: '招生老师', minWidth: 80},
                    {field: 'tel', title: '电话', minWidth: 80},
                    {field: 'identity', title: '身份证', minWidth: 80},
                    {field: 'originalPrice', title: '报名费', minWidth: 80},
                    {field: 'sendTime', title: '短信时间', minWidth: 80},
                    {field: 'activate', title: '状态', minWidth: 80,templet:function (d) {
                            if (d.activate === 1){
                                return '未激活'
                            }else if (d.activate === 2){
                                return '已激活'
                            }else {
                                return ''
                            }
                        }},
                    {field: 'remark', title: '备注', minWidth: 80},
                    {title: '操作', toolbar: '#businesses-networkSchool-option', maxWidth: 40},
                ]],

            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            console.log(params);
            return params;
        }

        // $(document).on("click", ".add_project_student", function () {
        //     var lvalue = $.parseJSON($(this).attr("value"));
        //
        //     $("#businesses-networkSchool-stubatch-select").val(lvalue.batchId);
        //     $("#businesses-networkSchool-stucollege-select").val(lvalue.collegeId);
        //     $("#businesses-networkSchool-level-select").val(lvalue.level);
        //     $("#businesses-networkSchool-major-select").val(lvalue.majorId);
        //     $("#businesses-networkSchool-stuName-input").val(lvalue.realName);
        //     $("#businesses-networkSchool-stuIdidentity-input").val(lvalue.identity);
        //     $("#businesses-networkSchool-stuTel-input").val(lvalue.tel);
        //     $("#businesses-networkSchool-username-input").val(lvalue.username);
        //     $("#businesses-networkSchool-cboType-select").val(lvalue.subjectId);
        //     $("#businesses-networkSchool-originalPrice-select").val(lvalue.originalPrice);
        //     layui.form.render("select");//动态选择
        //     $query.click();
        // });
    });
</script>